<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% String closeWindowAfterSessionExp = ( String ) request.getAttribute( "closeWindowAfterSessionExp" ); %>
<html>
<head><title>Scalar Soft - ChipTrac</title>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/release_send_mail.js"></script>
<style>
<!--
a.nav:link   { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: underline }
a.nav:visited { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
a.nav:active { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: underline }
a.nav:hover  { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none; color: red }
.HEADING     { cursor: hand; font-family: Verdana,Arial,San Serif; font-size: 11px; color: blue; font-weight: none; border: 1 solid #000000 }
.LINKSOFF    { display: none; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000000; }
.LINKSON     { display: inline; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000000; }
-->
</style>
<Script Language="VBscript">
    // Copyright 2001 Stephen Hayes (steve@obtsolutions.co.uk)
    // OBT Solutions UK (http://www.obtsolutions.co.uk)
    // Permission granted to SimplytheBest.net to feature script in its
    // DHTML script collection at http://simplythebest.net/info/dhtml_scripts.html
    <!--
    Option Explicit
    DIM menuID,menuObj,cellBk
    SUB ShowHide(menuID)
    menuObj = "Link" & menuID
    cellbk = "Head" & menuID
    // CHECK IF OPEN
    if document.all.item(menuObj).className = "LINKSON" then    'IF MENU OPEN THEN CLOSE
    document.all.item(menuObj).className = "LINKSOFF"
    document.all.item(cellBk).style.backgroundColor = "#FFFFFF"   ' SET CELL BACKGROUND COLOUR BLUE
    ELSE
    document.all.item(menuObj).className = "LINKSON"               ' OPEN MENU
    document.all.item(cellBk).style.backgroundColor = "#FFFFFF"  ' SET CELL BACKGROUND COLOUR RED
    END IF
    END SUB
    -->
</Script>

<script type="text/javascript">

var emailCount  = 0;
var OnlyOneflag = false;
function newEmail( fieldName, fieldLabel, fontId, colorCode )
{
    var form = document.releaseSendMailForm;
    //alert( " fieldName:" + fieldName + " fieldLabel:" + fieldLabel + " fontId:" + fontId )
    var htmlText;
	var pa=document.getElementById( fontId );
    var emailUserCtrl;
    var emailUserCrtlCount;
    var hiddenCrtlName;
    if( fontId == 'font1' )
    {
        emailUserCrtlCount = document.releaseSendMailForm.hiddenToUsers.length;
        hiddenCrtlName = "hiddenToUsers";
    }
    else if( fontId == 'font2' )
    {
        emailUserCrtlCount = document.releaseSendMailForm.hiddenCcUsers.length;
        hiddenCrtlName = "hiddenCcUsers";
    }
    else if( fontId == 'font3' )
    {
        emailUserCrtlCount = document.releaseSendMailForm.hiddenBccUsers.length;
        hiddenCrtlName = "hiddenBccUsers";
    }
    if( typeof( emailUserCrtlCount ) == "undefined" )
    {
        emailUserCrtlCount = 1;
    }

    if( document.getElementById('link0').className == 'LINKSOFF')
    {
        document.releaseSendMailForm.divCcDisplayStyle.value = "CLASS='LINKSOFF'";
    }
    else
    {
        document.releaseSendMailForm.divCcDisplayStyle.value = "CLASS='LINKSNO'";
    }
    
    if( document.getElementById('link1').className == 'LINKSOFF')
    {
        document.releaseSendMailForm.divBccDisplayStyle.value = "CLASS='LINKSOFF'";
    }
    else
    {
        document.releaseSendMailForm.divBccDisplayStyle.value = "CLASS='LINKSNO'"
    }

    form.action = '<%=chipTracContext%>/releaseSendMail.do?action=addMore&recipientType=' + fieldName + '&controlIndex=' + emailUserCrtlCount;
    form.submit();
}

function submitSendMail()
{
    var form = document.releaseSendMailForm;
    var emailUserCrtlCount = 0;

    /*for( var x = 0 ; x < form.elements.length ; x++ )
    {
       var tmpElement = form.elements[x];
       alert(" Element Name : " + tmpElement.name + " Type :" + tmpElement.type + " Value :" + tmpElement.value);
    }*/

    if( document.getElementById('link0').className == 'LINKSOFF')
    {
        emailUserCrtlCount = document.releaseSendMailForm.hiddenCcUsers.length;
        if( typeof ( emailUserCrtlCount ) == "undefined" )
        {
            form['ccRecipientsEmailsList[0].emailUser'].value = "";
        }
        else
        {
            for ( var i = 0; i < emailUserCrtlCount; i++ )
            {
                form['ccRecipientsEmailsList[' + i + '].emailUser'].value = "";
            }
        }
    }

    if( document.getElementById('link1').className == 'LINKSOFF')
    {
        emailUserCrtlCount = document.releaseSendMailForm.hiddenBccUsers.length;
        if( typeof ( emailUserCrtlCount ) == "undefined" )
        {
            form['bccRecipientsEmailsList[0].emailUser'].value = "";
        }
        else
        {
            for ( var i = 0; i < emailUserCrtlCount; i++ )
            {
                form['bccRecipientsEmailsList[' + i + '].emailUser'].value = "";
            }
        }
    }

    if( document.getElementById('link0').className == 'LINKSOFF')
    {
        document.releaseSendMailForm.divCcDisplayStyle.value = "CLASS='LINKSOFF'";
    }
    else
    {
        document.releaseSendMailForm.divCcDisplayStyle.value = "CLASS='LINKSNO'";
    }
    if( document.getElementById('link1').className == 'LINKSOFF')
    {
        document.releaseSendMailForm.divBccDisplayStyle.value = "CLASS='LINKSOFF'";
    }
    else
    {
        document.releaseSendMailForm.divBccDisplayStyle.value = "CLASS='LINKSNO'"
    }

    if (  ( validateTo() == true ) && ( validateCC() == true ) && ( validateBCC() == true ) && ( validateSubject() == true ) && ( validateMessage() == true )  )
    {
        form.action = '<%=chipTracContext%>/releaseSendMail.do?action=save';
        form.submit();
    }
}

</script>

</head>
<BODY bgColor="#FDF5E6" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
    <% if ( closeWindowAfterSessionExp == null ) { %>
    <html:form action="/releaseSendMail.do" type="com.scalar.chiptrack.operations.release.forms.ReleaseSendMailForm">
    <table bgcolor='#FFFFFF' border='0' cellpadding='0' cellspacing='0' width='100%' bordercolor='#993333'>
        <tr>
            <td>
                <table cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%" align=center>
                    <tr>
                        <td valign=center colspan='2' bgcolor="#993333" align='center'>
                            <font class='NArialW'>
                                <font color='#FFFFFF'>
                                    <img height=20 width='28' src="<%=chipTracContext%>/jsp/includes/images/email_icon.jpg">
                                    <logic:equal value="Assembly" name="releaseSendMailForm" property="processType">Assembly Release Mail</logic:equal>
                                    <logic:equal value="Test" name="releaseSendMailForm" property="processType">Test Release Mail</logic:equal>
                                </font>
                            </font>
                        </td>
                    </tr>
                    <tr>
                        <td colspan='2'><chiptrack:info styleClass="NArialL"/></td>
                    </tr>
                    <tr>
                        <td colspan='2'><chiptrack:errors styleClass="NArialL"/></td>
                    </tr>
                    <tr>
                        <td colspan='2' align='right'>
                            <a href="javascript:window.close();" title='Click here to close this window' onMouseOver="window.status='Click here to close this window';return true"><font style="font-weight:bold" class='NArialS'>[Close this window]</font></a>
                        </td>
                    </tr>
                    <tr>
                        <td colspan='2'>
                            <img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif">
                            <html:hidden property="releaseId" />
                            <html:hidden property="processType" />
                            <html:hidden property="divCcDisplayStyle" />
                            <html:hidden property="divBccDisplayStyle" />

                            <bean:define id="divCcDisplayStyleObj" name="releaseSendMailForm" property="divCcDisplayStyle" />
                            <bean:define id="divBccDisplayStyleObj" name="releaseSendMailForm" property="divBccDisplayStyle" />
                        </td>
                    </tr>
                    <tr align="right">
                        <td colspan='2' align="right">
                            <table cellpadding='0' cellspacing='0' border='0' width='100%'>
                                <tr>
                                    <td width="70%">&nbsp;</td>
                                    <td width="30%" class='NArialS'>
                                        <font color='orange'><li>Type Email Address, separated by commas.<li>You can also other emails by click on <b>[+]</b></font>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td width="10%">&nbsp;</td>
                        <td width="95%" bgcolor='#FDF5E6'><INPUT align="left" border="0" maxLength=100 name="txtErrMsg" size="100"  style="BACKGROUND-COLOR:#FDF5E6; BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 10pt;font-weight:bold " value="" readOnly></td>
                    </tr>
                    <tr><td colspan='2'><img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <table cellpadding='0' cellspacing='0' border='0' width='100%' class='NArialL'>
                                <tr>
                                    <td width="15%"><font color='#003333'>FROM:</font></td>
                                    <td width="85%"><bean:write name="releaseSendMailForm" property="fromUser"/></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <table cellpadding='0' cellspacing='0' border='0' width='100%' class='NArialL'>
                                <nested:iterate id="sendMailObj" name="releaseSendMailForm" property="toRecipientsEmailsList" indexId="emailIndex" type="com.scalar.chiptrack.operations.release.ReleaseSendMail">
                                    <tr>
                                        <td width="15%" class='NArialL'>
                                            <font color='#990000'>TO:</font>
                                            <% if( emailIndex.intValue() == 0 ) { %>
                                            <br><br>
                                            <a ID='head0' CLASS="HEADING" ONCLICK='ShowHide(0)'><font class='NArialS'>[Show CC]</font></a>
                                            <br>
                                            <a ID='head1' CLASS="HEADING" ONCLICK='ShowHide(1)'><font class='NArialS'>[Show BCC]</font></a>
                                            <% } %>
                                        </td>
                                        <td width='80%'>
                                            <nested:text styleClass="txfield" size="83" property="emailUser" />
                                            <% if( emailIndex.intValue() == 0 ) { %>
                                            <a href="javascript:newEmail( 'toUsers', 'TO', 'font1', '#990000' )" title='Click to add other Emails'><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center></a>
                                            <% } %>
                                            <input type="hidden" name="hiddenToUsers">
                                        </td>
                                        <td width='5%' align='left'>&nbsp;</td>
                                    </tr>
                                </nested:iterate>
                                <tr><td colspan='7'><FONT id="font1"></FONT></TD></TR>
                            </table>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <div ID='link0' <%=divCcDisplayStyleObj%>>
                            <table cellpadding='0' cellspacing='0' border='0' width='100%' class='NArialL'>
                                <nested:iterate id="sendMailObj" name="releaseSendMailForm" property="ccRecipientsEmailsList" indexId="emailIndex" type="com.scalar.chiptrack.operations.release.ReleaseSendMail">
                                    <tr>
                                        <td width="15%" class='NArialL'>
                                            <font color='#990000'>CC:</font>
                                            <% if( emailIndex.intValue() == 0 ) { %>
                                            <br><br><a CLASS="HEADING" ONCLICK='ShowHide(0)'><font class='NArialS'>[Hide CC]</font></a>
                                            <% } %>
                                        </td>
                                        <td width='80%'>
                                            <nested:text styleClass="txfield" size="83" property="emailUser" />
                                            <% if( emailIndex.intValue() == 0 ) { %>
                                            <a href="javascript:newEmail( 'ccUsers', 'CC', 'font2', '#660033' )" title='Click to add other Emails'><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center></a>
                                            <% } %>
                                            <input type="hidden" name="hiddenCcUsers">
                                        </td>
                                        <td width='5%' align='left'>&nbsp;</td>
                                    </tr>
                                </nested:iterate>
                                <tr><td colspan='7'><FONT id="font2"></FONT></TD></TR>
                            </table>
                            </div>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <div ID='link1' <%=divBccDisplayStyleObj%>>
                            <table cellpadding='0' cellspacing='0' border='0' width='100%' class='NArialL'>
                                <nested:iterate id="sendMailObj" name="releaseSendMailForm" property="bccRecipientsEmailsList" indexId="emailIndex" type="com.scalar.chiptrack.operations.release.ReleaseSendMail">
                                    <tr>
                                        <td width="15%" class='NArialL'>
                                            <font color='#990000'>BCC:</font>
                                            <% if( emailIndex.intValue() == 0 ) { %>
                                            <br><br><a CLASS="HEADING" ONCLICK='ShowHide(1)'><font class='NArialS'>[Hide BCC]</font></a>
                                            <% } %>
                                        </td>
                                        <td width='80%'>
                                            <nested:text styleClass="txfield" size="83" property="emailUser" />
                                            <% if( emailIndex.intValue() == 0 ) { %>
                                            <a href="javascript:newEmail( 'bccUsers', 'BCC', 'font3', '#003333' )" title='Click to add other Emails'><img border=0 src='<%=chipTracContext%>/jsp/includes/images/add.jpg' height='15' width='20' align=center></a>
                                            <% } %>
                                            <input type="hidden" name="hiddenBccUsers">
                                        </td>
                                        <td width='5%' align='left'>&nbsp;</td>
                                    </tr>
                                </nested:iterate>
                                <tr><td colspan='7'><FONT id="font3"></FONT></TD></TR>
                            </table>
                            </div>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr><td colspan='2'><img height=5 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <table cellpadding='0' cellspacing='0' border='0' width='100%' class='NArialL'>
                                <tr>
                                    <td width="15%" class="NArialL">Subject:</td>
                                    <td width='85%'><html:text name="releaseSendMailForm" property='subject' size='83' maxlength='200' styleClass='txfield'/></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img height=15 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="NArialL">Message:</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td>
                            <html:textarea cols="100" rows="5" name="releaseSendMailForm" property="message"  styleClass="txfield"/>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td >
                            <table cellpadding='0' cellspacing='0' border='0' width='100%' class='NArialL'>
                                <tr>
                                    <td><font class="NArialL">&nbsp;</font></td>
                                    <td  align="center">
                                        <font class='NArialL'>
                                           Attach as <html:radio name="releaseSendMailForm" property='attachMIMEType' value="HTML" />&nbsp;HTML Format &nbsp;&nbsp;
                                        </font>
                                        <font class='NArialL'>
                                           <html:radio name='releaseSendMailForm' property='attachMIMEType' value="PDF"  />&nbsp;Adobe PDF Version&nbsp;&nbsp;
                                        </font>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
                    <tr>
                        <td colspan='2' align=center>
                            <logic:notEqual name="isConfirm" value="true" >
                                <a href="javascript:submitSendMail()"><img onMouseOver="window.status='Click here send a mail';return true"  border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            </logic:notEqual>
                            <logic:equal name="isConfirm" value="true" >
                                <a href="javascript:submitSendMail()"><img onMouseOver="window.status='Click here send a mail';return true"  border="0" src="<%=chipTracContext%>/jsp/includes/images/confirm.gif" ></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            </logic:equal>
                            <a href="javascript:window.close();"><img onMouseOver="window.status='Click here to close this window';return true"  border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"></a>
                        </td>
                    </tr>
                    <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                    <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                    <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                    <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                </table>
            </td>
        </tr>
    </table>
    </html:form>
    <% } else { %>
    <table cellpadding='0' cellspacing='0' bgcolor='FDF5E6' border="0" width="100%"  height="100%" align=center>
        <tr>
            <td>
                <table align="center" border="0" width="40%" bgcolor="#FDF5E6">
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><font class="NArialL" ><font color="red">Session has been time out , Please close this window and login again.</font></font></td></tr>
                    <tr><td>&nbsp;</td></tr>
                    <tr><td align="center" ><a href="javascript:window.close();"><font class='NArialL'>[Close this window]</font></a></td></tr>
                </table>
            </td>
       </tr>
       <tr><td>&nbsp;</td></tr>
    </table>
    <% } %>
</BODY>
</html>
